<?php
/**
 * Created by PhpStorm.
 * User: Bu
 * Date: 2018/1/15
 * Time: 17:19
 */

namespace app\admin\controller;


use think\Controller;
use think\Db;

class Order extends Controller
{
    public function index()
    {
        #查询订单表
        $uid = session('id');
        #地址表信息(address)
        $addressdata = Db::table('address')->where('id',$uid)->find();
        #接收者用户名字
        $username =$addressdata['names'];
        #地址信息
        $address = $addressdata['address'];
        #订单信息表(order)
       $orderData =  Db::table('order')->select();
//       halt($orderData);
       $data=[];

       foreach ($orderData as $k=>$v){
           $username =Db::table('address')->where('id',$v['address_id'])->find();
           $orderData[$k]['username'] = $username['names'];
           $orderData[$k]['list']=Db::table('ordergoods')->where('oid',$v['id'])->select();
       }
//       halt($orderData);
//       foreach($data as $k =>$v)
//       {
//           foreach ($v as $k1=>$v1 )
//           {
//               $odata = Db::table('order')->where('id',$v1['oid'])->find();
//
//               $data[$k][$k1]['memo'] = $odata['memo'] ;
//               $data[$k][$k1]['order_num'] = $odata['order_num'] ;
//               $data[$k][$k1]['status'] = $odata['status'] ;
//               $data[$k][$k1]['username'] = $odata['username'] ;
//           }
//           $data[$k]['status']= $odata['status'];
//       }

//       halt($data);
//       halt($orderData);
        #查询订单表
        #查询订单商品表(ordergoods)
        $orderModel =new \app\common\model\Order();
        $orderGoodsData = $orderModel->ordergoods;
//        dump($orderGoodsData);
        return view('',compact('orderGoodsData','orderData','data'));
    }
    public function ajaxPush()
    {
        $id= input('sid');
        Db::table('order')->update(['status' => 2,'id'=>$id]);
        return 1;
    }
}